const http = require('http')
const cheerio = require('cheerio');
const download = require('download');
const HOST = 'http://web.itheima.com/'
// https://movie.douban.com/explore
// http://web.itheima.com/teacher.html
let req = http.request(HOST + 'teacher.html',res => {
    // console.log(res)
    let chunks = []
    res.on('data',chunk => {
        chunks.push(chunk)
    })

    res.on('end',() => {
        // console.log(Buffer.concat(chunks).toString('utf-8'))
        let htmlStr = Buffer.concat(chunks).toString('utf-8')
        let $ = cheerio.load(htmlStr)
        // console.log($('.tea_main .tea_con .tea_txt ul li > img').attr('src'))
        // console.log($('.tea_main .tea_con .tea_txt ul li > img').length)
        // let imgs = []
        // $('.tea_main .tea_con .tea_txt ul li > img').each((index,item) => {
        //     console.log(HOST+$(item).attr('src'))
        //     imgs.push(HOST+$(item).attr('src'))
        // })
        // console.log(imgs)

        let imgs = Array.prototype.map.call($('.tea_main .tea_con .tea_txt ul li > img'),item => HOST+$(item).attr('src'))
        // let imgs =$('.tea_main .tea_con .tea_txt ul li > img').map((index,item)=>HOST+$(item).attr('src'))
        
        // console.log(imgs)
        // Promise.all(imgs.map(x=>download(x,'dist'))).then(()=>{
        //     console.log('files download!');
        // })
    })
})

req.end()